home *** CD-ROM | disk | FTP | other *** search
/ Apple WWDC 1996 / WWDC96_1996 (CD).toast / Technology Materials / QuickTime VR / MacOS / QuickDraw™ 3D 1.0.6F4 SDK / Development / 3DMF parser / 1.0 version / MF3DPC / MFGROUPS.C < prev    next >
Encoding:
C/C++ Source or Header  |  1995-11-07  |  3.5 KB  |  141 lines  |  [TEXT/dosa]

  1. /*==============================================================================
  2.  *
  3.  *    File:        MFGROUPS.C
  4.  *
  5.  *    Function:    Handle group state and attribute states.
  6.  *
  7.  *    Version:    Metafile:    Version 1.0 3DMF files
  8.  *                Package:    Release #2 of this code
  9.  *
  10.  *    Author(s):    Rick Wong (RWW), Duet Development Corp.
  11.  *                John Kelly (JRK), Duet Development Corp.
  12.  *
  13.  *    Copyright:    (c) 1995 by Apple Computer, Inc., all rights reserved.
  14.  *
  15.  *    Change History (most recent first):
  16.  *        FB8_JRK    Segmentation
  17.  *        Fabio    Changed file name to 8 characters
  18.  *        F2R_RWW Use the simple object model, eliminating the need for most
  19.  *                of the meat of all these routines.
  20.  *        F2N_RWW    File created.
  21.  *==============================================================================
  22.  */
  23.  
  24. #include "MFGROUPS.H"
  25.  
  26. #include "MFERRORS.H"
  27. #include "MFSUBOBJ.H"
  28. #include "MFASSERT.H"
  29. #include "MFINTOBJ.H"
  30. #include "MFMACROS.H"
  31. #include "MFMEMORY.H"
  32.  
  33. #if defined(applec) || defined(__MWERKS__) || defined(THINK_C)
  34. #pragma segment __MF3D__
  35. #endif
  36.  
  37. /*==============================================================================
  38.  *    MF3D_InitGroup
  39.  *
  40.  *    Setup internal file record group stuff
  41.  *==============================================================================
  42.  */
  43. MF3DErr
  44. MF3D_InitGroup(
  45.     MF3D_FilePtr    ioMetafile)
  46. {
  47.     MF3DErr    result;
  48.  
  49.     MFASSERT(ioMetafile->readWrite == MF3D_MetafileRead);
  50.  
  51.     result = kMF3DNoErr;
  52.  
  53.     ioMetafile->groupState.traversalFlags = MF3DDisplayGroupDefaultFlags;
  54.     ioMetafile->groupState.parent = NULL;
  55.  
  56.     return result;
  57. }
  58.  
  59. /*==============================================================================
  60.  *    MF3D_PushGroup
  61.  *
  62.  *    Make a copy of the current group and push it onto the group stack
  63.  *==============================================================================
  64.  */
  65. MF3DErr
  66. MF3D_PushGroup(
  67.     MF3D_FilePtr    ioMetafile)
  68. {
  69.     MF3D_GroupStatePtr    oldGroup;
  70.     MF3DErr                result;
  71.  
  72.     MFASSERT(ioMetafile->readWrite == MF3D_MetafileRead);
  73.  
  74.     result = kMF3DNoErr;
  75.  
  76.     MF3D_Allocate(oldGroup);
  77.  
  78.     if (result == kMF3DNoErr)
  79.     {    oldGroup->traversalFlags =
  80.                 ioMetafile->groupState.traversalFlags;
  81.         oldGroup->parent = ioMetafile->groupState.parent;
  82.         ioMetafile->groupState.parent = oldGroup;
  83.     }
  84.  
  85.     return result;
  86. }
  87.  
  88. /*==============================================================================
  89.  *    MF3D_PopGroup
  90.  *
  91.  *    Pop the group stack
  92.  *==============================================================================
  93.  */
  94. MF3DErr
  95. MF3D_PopGroup(
  96.     MF3D_FilePtr    ioMetafile)
  97. {
  98.     MF3D_GroupStatePtr    parentGroup;
  99.     MF3DErr                result;
  100.  
  101.     MFASSERT(ioMetafile->readWrite == MF3D_MetafileRead);
  102.  
  103.     result = kMF3DNoErr;
  104.  
  105.     parentGroup = ioMetafile->groupState.parent;
  106.     if (ioMetafile->groupState.parent == NULL)
  107.         result = kMF3DErrTooManyEndGroups;
  108.  
  109.     if (result == kMF3DNoErr)
  110.     {    ioMetafile->groupState.parent = parentGroup->parent;
  111.         MF3D_Free(parentGroup);
  112.     }
  113.  
  114.     return result;
  115. }
  116.  
  117. /*==============================================================================
  118.  *    MF3D_DisposeGroup
  119.  *
  120.  *    Clean up top-level group pointers
  121.  *==============================================================================
  122.  */
  123. MF3DErr
  124. MF3D_DisposeGroup(
  125.     MF3D_FilePtr    ioMetafile)
  126. {
  127.     MF3DErr    result;
  128.  
  129.     MFASSERT(ioMetafile->readWrite == MF3D_MetafileRead);
  130.  
  131.     result = kMF3DNoErr;
  132.  
  133.     if (ioMetafile->groupState.parent != NULL)
  134.     {    result = kMF3DErrNotEnoughEndGroups;
  135.         MF3D_PopGroup(ioMetafile);            /* errors ignored */
  136.         MF3D_DisposeGroup(ioMetafile);        /* because we already have one */
  137.     }
  138.  
  139.     return result;
  140. }
  141.